using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ShopProduct : Admin, IRequiresSessionState
{
	protected DropDownList QuickSearch;
	protected DropDownList show_type;
	protected CheckBox CheckBox1;
	protected DropDownList DetailSearchType;
	protected TextBox DetailSearchName;
	protected Button AdminSearch;
	protected GridView GridView1;
	protected Label PagePanel;
	protected Button btnApprove;
	protected Button btnUnApprove;
	protected Button AllowSale_Button;
	protected Button StopSale;
	protected Button DisableSale;
	protected Button Elite_Button;
	protected Button CancleElite;
	protected Button Button1;
	protected Button Button2;
	protected Button Button3;
	protected Button Button4;
	protected Button Delete_Button;
	protected DropDownList ProductNewClass;
	protected Button SetProductNewClassButton;
	protected string m_QuickSearch;
	protected string m_DetailSearch;
	protected string m_DetailSearchName;
	protected string m_OrderBy;
	protected string m_OrderByType;
	protected string WhereStr = "";
	protected string OrderByStr = "";
	protected string linkHead = "";
	private bool m_tag = true;
	private IDbDataParameter param = null;
	private Shop_Product _product = null;
	private Shop_Class _Class = null;
	private UserBll _user = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_Product m_product
	{
		get
		{
			Shop_Product product;
			if (this._product == null)
			{
				this._product = new Shop_Product(this.conn);
				product = this._product;
			}
			else
			{
				product = this._product;
			}
			return product;
		}
	}
	protected Shop_Class m_Class
	{
		get
		{
			Shop_Class @class;
			if (this._Class == null)
			{
				this._Class = new Shop_Class(this.conn);
				@class = this._Class;
			}
			else
			{
				@class = this._Class;
			}
			return @class;
		}
	}
	protected UserBll m_user
	{
		get
		{
			UserBll user;
			if (this._user == null)
			{
				this._user = new UserBll(this.conn);
				user = this._user;
			}
			else
			{
				user = this._user;
			}
			return user;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(20))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Product");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			SiteConfigBll siteConfigBll = new SiteConfigBll();
			if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0" && !base.admin.CheckSuperAdmin())
			{
				this.DetailSearchType.Items.Remove(new ListItem("商品所在地", "product_place"));
			}
			this.ProductNewClass.DataSource = this.m_Class.GetAllClassNameFillDropDown();
			this.ProductNewClass.DataBind();
			this.BindList();
		}
	}
	protected void BindList()
	{
		int num = Fetch.GetID("page");
		if (num == 0)
		{
			num = 1;
		}
		this.QuestString();
		int maxperpage = 15;
		if (this.GridView1.PageSize != 0)
		{
			maxperpage = int.Parse(this.GridView1.PageSize.ToString());
		}
		if (this.param != null)
		{
			this.GridView1.DataSource = this.m_product.GetAllProduct(num, maxperpage, this.WhereStr, this.OrderByStr, new IDbDataParameter[]
			{
				this.param
			});
		}
		else
		{
			this.GridView1.DataSource = this.m_product.GetAllProduct(num, maxperpage, this.WhereStr, this.OrderByStr);
		}
		this.GridView1.DataBind();
		this.PagePanel.Text = this.m_product.GetPagePanel(this.linkHead);
	}
	protected void QuestString()
	{
		this.m_QuickSearch = Fetch.Get("QuickSearch");
		if (this.m_QuickSearch != string.Empty && this.m_tag)
		{
			this.QuickSearch.SelectedValue = this.m_QuickSearch;
		}
		else
		{
			this.m_QuickSearch = this.QuickSearch.SelectedValue;
		}
		if (this.m_QuickSearch != "all_product")
		{
			string text = this.m_QuickSearch;
			switch (text)
			{
			case "on_sale":
				this.WhereStr += "and EnableSale=1";
				break;
			case "stop_sale":
				this.WhereStr += "and EnableSingleSell=0";
				break;
			case "on_stock":
				this.WhereStr += "and EnableSale=0";
				break;
			case "on_top":
				this.WhereStr += "and IsPageElite=1";
				break;
			case "saler_recommend":
				this.WhereStr += "and IsElite=1";
				break;
			case "all_approve":
				this.WhereStr += "and IsApprove=0";
				break;
			}
			this.linkHead = "&QuickSearch=" + this.m_QuickSearch;
		}
		this.m_DetailSearch = Fetch.Get("DetailSearch");
		if (this.m_DetailSearch != string.Empty && this.m_tag)
		{
			this.DetailSearchType.SelectedValue = this.m_DetailSearch;
		}
		else
		{
			this.m_DetailSearch = this.DetailSearchType.SelectedValue;
		}
		this.m_DetailSearchName = Fetch.Get("DetailSearchName");
		if (this.m_DetailSearchName != string.Empty && this.m_tag)
		{
			this.DetailSearchName.Text = this.m_DetailSearchName;
		}
		else
		{
			this.m_DetailSearchName = this.DetailSearchName.Text;
		}
		if (this.m_DetailSearchName != "" && this.m_DetailSearchName != string.Empty)
		{
			string text = this.m_DetailSearch;
			if (text != null)
			{
				if (!(text == "product_name"))
				{
					if (!(text == "saler_name"))
					{
						if (!(text == "product_class"))
						{
							if (text == "product_place")
							{
								this.WhereStr += "and ProductPlace like '%'+@ProductPlace+'%'";
								this.param = this.conn.CreateParameter("@ProductPlace", DbType.String, this.m_DetailSearchName);
							}
						}
						else
						{
							this.WhereStr += "and ClassID in (Select ClassID From [HLShop_Class] Where ClassName like '%'+@ClassName+'%')";
							this.param = this.conn.CreateParameter("@ClassName", DbType.String, this.m_DetailSearchName);
						}
					}
					else
					{
						this.WhereStr += "and SalerID in(Select UserID From [HL_User] Where UserName like '%'+ @UserName +'%')";
						this.param = this.conn.CreateParameter("@UserName", DbType.String, this.m_DetailSearchName);
					}
				}
				else
				{
					this.WhereStr += "and ProductName like '%'+ @ProductName +'%'";
					this.param = this.conn.CreateParameter("@ProductName", DbType.String, this.m_DetailSearchName);
				}
			}
			string text2 = this.linkHead;
			this.linkHead = string.Concat(new string[]
			{
				text2,
				"&DetailSearch=",
				this.m_DetailSearch,
				"&DetailSearchName=",
				base.Server.UrlEncode(this.m_DetailSearchName)
			});
		}
		this.m_OrderBy = Fetch.Get("order");
		if (this.m_OrderBy != string.Empty && this.m_tag)
		{
			this.show_type.SelectedValue = this.m_OrderBy;
		}
		else
		{
			this.m_OrderBy = this.show_type.SelectedValue;
		}
		this.m_OrderByType = Fetch.Get("ordertype");
		if (this.m_OrderByType != string.Empty && this.m_tag)
		{
			if (this.m_OrderByType == "1")
			{
				this.CheckBox1.Checked = true;
			}
			else
			{
				this.CheckBox1.Checked = false;
			}
		}
		else
		{
			if (this.CheckBox1.Checked)
			{
				this.m_OrderByType = "1";
			}
			else
			{
				this.m_OrderByType = "0";
			}
		}
		if (this.m_OrderByType == "1")
		{
			this.m_OrderByType = "desc";
		}
		else
		{
			this.m_OrderByType = "";
		}
		if (this.m_OrderBy != "ProductID")
		{
			string text = this.m_OrderBy;
			if (text != null)
			{
				if (!(text == "BeginDate"))
				{
					if (!(text == "StandPrice"))
					{
						if (!(text == "Hits"))
						{
							if (text == "Stocks")
							{
								this.OrderByStr = "Stocks " + this.m_OrderByType;
							}
						}
						else
						{
							this.OrderByStr = "Hits " + this.m_OrderByType;
						}
					}
					else
					{
						this.OrderByStr = "StandPrice " + this.m_OrderByType;
					}
				}
				else
				{
					this.OrderByStr = "BeginDate " + this.m_OrderByType;
				}
			}
			string text2 = this.linkHead;
			this.linkHead = string.Concat(new string[]
			{
				text2,
				"&order=",
				this.m_OrderBy,
				"&ordertype=",
				(this.m_OrderByType == "desc") ? "1" : "0"
			});
		}
		SiteConfigBll siteConfigBll = new SiteConfigBll();
		if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0")
		{
			if (HttpContext.Current.Request.Cookies["Howave_CityArea"] != null)
			{
				string str = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["Howave_CityArea"].Value);
				this.WhereStr = this.WhereStr + "and ProductPlace like '%" + str + "%'";
			}
			else
			{
				if (HttpContext.Current.Request.Cookies["Howave_ProvinceArea"] != null)
				{
					string str2 = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["Howave_ProvinceArea"].Value);
					this.WhereStr = this.WhereStr + "and ProductPlace like '%" + str2 + "%'";
				}
			}
		}
		if (this.WhereStr != "")
		{
			this.WhereStr = "and" + this.WhereStr;
			this.WhereStr = this.WhereStr.Replace("andand", "where");
		}
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		bool flag = false;
		string text = e.CommandName.ToString();
		switch (text)
		{
		case "EnableSale":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "StopSale":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "DisableSale":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "PageElite":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "CanclePageElite":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "IsHot":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "CancleIsHot":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "OnTop":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "CancleOnTop":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "Delete":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "EnableApprove":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		case "DisableApprove":
			if (base.admin.CheckAdminPower(20))
			{
				flag = true;
			}
			break;
		}
		if (!flag)
		{
			base.WriteRightErrMsg();
		}
		string text2 = base.Request["chk_select"];
		if (text2 != "")
		{
			this.m_product.EditSaleProductProtity(text2, e.CommandName.ToString());
			string text3 = e.CommandName.ToString();
			if (text3 != "Delete")
			{
				text3 = "Check";
			}
			base.WriteLog(text3, Language.GetAdminMsg("Log/ObjectID", text2), "Product");
		}
		this.m_tag = false;
		this.BindList();
	}
	protected void AdminSearch_Click(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void QuickSearch_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void CheckBox1_OnChange(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void show_type_OnChange(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
			Literal literal = (Literal)e.Row.FindControl("ProductOnSale");
			Literal literal2 = (Literal)e.Row.FindControl("OnTop");
			Literal literal3 = (Literal)e.Row.FindControl("IsHot");
			Literal literal4 = (Literal)e.Row.FindControl("IsPageElite");
			Literal literal5 = (Literal)e.Row.FindControl("HavePic");
			HiddenField hiddenField = (HiddenField)e.Row.FindControl("ImgUrl");
			HiddenField hiddenField2 = (HiddenField)e.Row.FindControl("ProductOnShopSale");
			HyperLink hyperLink = (HyperLink)e.Row.FindControl("Saler");
			int id = int.Parse(hyperLink.Text);
			hyperLink.Text = this.m_user.GetUserNameByID(id);
			if (literal.Text == "True" && hiddenField2.Value == "True" && e.Row.Cells[5].Text != "0")
			{
				literal.Text = "√";
			}
			else
			{
				literal.Text = "×";
			}
			literal2.Text = ((literal2.Text == "True") ? "顶" : "");
			literal3.Text = ((literal3.Text == "True") ? "热" : "");
			literal4.Text = ((literal4.Text == "True") ? "荐" : "");
			literal5.Text = ((hiddenField.Value != "") ? "图" : "");
		}
	}
	protected void SetProductNewClassButton_Click(object sender, EventArgs e)
	{
		string text = base.Request["chk_select"];
		if (text != null && !(text == string.Empty))
		{
			string sql = string.Concat(new string[]
			{
				"Update HLShop_Product set ClassID=",
				this.ProductNewClass.SelectedValue,
				" where ProductID in(",
				text,
				")"
			});
			bool flag = this.conn.Execute(sql) >= 1;
			if (flag)
			{
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "");
			}
		}
	}
}
